package com.fjzx.androidframe.base.aop;

import android.view.View;

import com.fjzx.androidframe.base.aop.annotation.SingleClick;
import com.fjzx.androidframe.global.util.XClickUtil;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;

/**
 * Aop 处理类，防止View快速点击
 *
 * @author xiongyongcong
 */
@Aspect
public class SingleClickAspect {
    private static final String TAG = "";
    private static final long DEFAULT_TIME_INTERVAL = 5000;

    @Pointcut("execution(@com.fjzx.androidframe.base.aop.annotation.SingleClick * *(..))")
    public void methodAnnotated() {
    }

    @Around("methodAnnotated()")
    public void aroundJoinPoint(ProceedingJoinPoint joinPoint) throws Throwable {
        try {
            View view = null;
            for (Object arg : joinPoint.getArgs()) {
                if (arg instanceof View) {
                    view = (View) arg;
                    break;
                }
            }
            if (view != null) {
                SingleClick singleClick = AspectJUtil.getMethodAnnotation(joinPoint, SingleClick.class);
                if (!XClickUtil.isFastDoubleClick(view, singleClick.value())) {
                    // 不是快速点击，执行原方法
                    joinPoint.proceed();
                }
            }
        } catch (Throwable throwable) {
            throwable.printStackTrace();
        }
    }
}
